Skip to content

Build Codex Git releases with LTO and PGO#2

Merged
ttaylorr-oai merged 3 commits into
codexfrom
ttaylorr/codex-git-lto-pgo
Jul 21, 2026
Merged

Build Codex Git releases with LTO and PGO#2
ttaylorr-oai merged 3 commits into
codexfrom
ttaylorr/codex-git-lto-pgo

Conversation

@ttaylorr-oai

Copy link
Copy Markdown
Collaborator

Summary

  • run Linux arm64 Codex release builds natively and smoke-test every bundle
  • build release artifacts with thin LTO for Clang targets and automatic LTO for GCC targets
  • train each release build with a short Codex-shaped PGO workload before the profile-use rebuild

Why

The current Codex release path inherits Git's default -O2 build and compiles each artifact once. LTO lets the compiler optimize across translation units; PGO lets the final binary use frequencies from the local Git operations Codex calls most often.

The PGO trainer intentionally avoids Git's full 1,048-script test suite. Git's built-in PROFILE=BUILD path runs that suite serially; recent upstream CI spends tens of minutes on full-suite coverage, while the focused local trainer took about 30 seconds. The trainer covers clone, status, untracked discovery, add, diff, commit, log, ref enumeration, repack, and fetch.

Approach

  • Keep release-only flags and make orchestration in config.mak.openai, copied into Git's ignored config.mak slot by the release workflow.
  • Use -flto=thin for Clang targets and -flto=auto for GCC targets.
  • Use LLVM raw profiles plus llvm-profdata on Clang targets and gcov profiles on GCC targets.
  • Gate GIT-CFLAGS on the instrumented build, training workload, merge, and profile-use rebuild so make strip install cannot start final compilation before the profile exists.
  • Verify final GIT-CFLAGS records both LTO and profile-use flags, then smoke-test every distribution.

Commit structure

  1. ci: run Codex Linux arm64 releases natively
  2. ci: build Codex Git releases with LTO
  3. ci: train Codex Git releases with PGO

Validation

  • clean local macOS arm64 LTO-only build; final GIT-CFLAGS contained -flto=thin and no profile flag
  • clean local macOS arm64 PGO make strip install; observed generation, trainer, LLVM profile merge, profile-use rebuild, strip, and install
  • installed macOS arm64 binary ran --version --build-options; final GIT-CFLAGS contained -flto=thin and -fprofile-instr-use=
  • git show --check for each commit
  • git diff --check, workflow YAML parse, and sh -n .github/workflows/codex-pgo-training.sh

The workflow now performs a second compilation pass and adds roughly 30 seconds of focused training per target, so its timeout increases from 30 to 60 minutes. This validates the build plumbing and artifact provenance; it does not claim a measured runtime speedup yet. Cross-platform PGO behavior remains for the draft PR matrix to exercise.

The release workflow cross-compiles Linux arm64 on an x64 runner
and skips the smoke test for arm64 POSIX bundles. That prevents
the workflow from executing the Linux artifact it just produced.

Run Linux arm64 on GitHub's arm64 runner and install native
development packages rather than configuring a foreign dpkg
architecture. All matrix entries can then run the existing
distribution smoke test.
Codex consumes Git release artifacts built with the Makefile's default
-O2 flags. The release job compiles each artifact without link-time
optimization.

Add a release-only config.mak.openai and copy it into Git's ignored
config.mak slot before building. Use thin LTO for Clang targets and
automatic LTO for GCC targets, then check GIT-CFLAGS records the
selected flag in every distribution job.

Keeping the setting in config.mak.openai avoids carrying release-only
policy in the upstream Makefile.
LTO can optimize across translation units, but the release job has no
execution profile for the status, diff, clone, fetch, and repack paths
Codex invokes frequently. Git's built-in profile target runs the
1,048-script test suite serially. That is too expensive for every
release target and weights test-harness paths more heavily than the
local workload.

Extend config.mak.openai with GCC and LLVM profile modes. Gate
GIT-CFLAGS on an instrumented build, run a short offline trainer,
merge LLVM raw profiles when needed, and rebuild with profile-use
flags. Each matrix entry runs on its target architecture, so it can
execute the instrumented binary.

Check that final GIT-CFLAGS includes a profile-use flag and increase
the timeout for the second compilation pass. The focused trainer took
about 30 seconds locally; the full macOS build/install validation
completed with thin LTO and LLVM profile-use enabled.
@ttaylorr-oai
ttaylorr-oai marked this pull request as ready for review July 21, 2026 22:45
@ttaylorr-oai
ttaylorr-oai merged commit 0d01927 into codex Jul 21, 2026
98 of 99 checks passed
@ttaylorr-oai
ttaylorr-oai deleted the ttaylorr/codex-git-lto-pgo branch July 21, 2026 22:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant